package com.ttc.mBackup;

import java.io.File;

import com.ttc.mBackup.BackupContacts.BackupContactActivity;
import com.ttc.mBackup.BackupImages.BackupInfoActivity;
import com.ttc.mBackup.BackupImages.ListImagesActivity;
import com.ttc.mBackup.BackupSMS.BackupSMSActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;

public class BackupActivity extends Activity {

	private ImageButton btnContacts;
	private ImageButton btnSMS;
	private ImageButton btnImages;
	private ImageButton btnAgent;
	
	/*Define BACKUPAGENT string Value*/
	public final static String KEY_ACTIVITY ="ROB";
	/*
	 * Folder External's Name **/
	public final static String DIR_NAME ="BACKUPSYSTEM";
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_backup);

		btnContacts = (ImageButton) findViewById(R.id.backup_btnContacts);
		btnSMS = (ImageButton) findViewById(R.id.backup_btnSMS);
		btnImages = (ImageButton) findViewById(R.id.backup_btnImages);
		btnAgent = (ImageButton) findViewById(R.id.backup_btnAgent);

		btnContacts.setOnClickListener(oclContacts);
		btnSMS.setOnClickListener(oclSMS);
		btnImages.setOnClickListener(oclImages);
		btnAgent.setOnClickListener(oclAgent);
		
	}

	OnClickListener oclContacts = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(BackupActivity.this, BackupContactActivity.class);
			startActivity(intent);

		}
	};

	OnClickListener oclSMS = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(BackupActivity.this, BackupSMSActivity.class);
			startActivity(intent);

		}
	};

	OnClickListener oclImages = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(BackupActivity.this, BackupInfoActivity.class);
			startActivity(intent);

		}
	};

	OnClickListener oclAgent = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// Start your task
			/*Create folder in First time use it*/
			 File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
		        		+File.separator+
		        		DIR_NAME);
		        if(!file.exists())
		        {
		        	file.mkdir();
		        }
		        File filein = new File("data/data/com.ttc.mBackup/SystemBackup");
		    	if(!filein.exists())
		    		{
		    			filein.mkdir();
		    	}
		    	
			Intent i = new Intent("com.ttc.mBackup.BackupAgent.BACKUPRESTORE");
			i.putExtra(KEY_ACTIVITY,true);
			startActivity(i);	
		}
	};
	

}
